﻿using System;
using System.Diagnostics;
using SGLL.Properties;
using System.Windows.Forms;
using System.Deployment.Application;

namespace SGLL
{
    public partial class FormMain : Form
    {
        //Variables
        public static Stopwatch stopwatch;
        //Form
        public FormMain()
        {
            InitializeComponent();
            stopwatch = new Stopwatch();
        }
        private void FormMain_Load(object sender, EventArgs e)
        {
            try
            {
                //Title
                if (ApplicationDeployment.IsNetworkDeployed) this.Text = string.Format("{0} versión {1}", Resources.ApplicationName, ApplicationDeployment.CurrentDeployment.CurrentVersion);
                //Status Bar
                toolStripStatusLabelComputer.Text = Environment.MachineName;
                toolStripStatusLabelUser.Text = Environment.UserName;
                toolStripStatusLabelCallsValue.Text = ClassFunctions.GetTotalCalls();
                toolStripStatusLabelLastCallValue.Text = ClassFunctions.GetLastCall();
            }
            catch (Exception exception)
            {
                ClassFunctions.ErrorLog(exception);
            }
        }
        //Menu Strip
        private void toolStripMenuItemCallLog_Click(object sender, EventArgs e)
        {
            FormCalls formCalls = new FormCalls();
            toolStripMenuItemCall.Enabled = false;
            LoadForm(formCalls);
        }
        private void toolStripMenuItemComplaints_Click(object sender, EventArgs e)
        {
            FormComplaints formComplaints = new FormComplaints();
            toolStripMenuItemComplaints.Enabled = false;
            LoadForm(formComplaints);
        }
        private void toolStripMenuItemConfiguration_Click(object sender, EventArgs e)
        {
            FormSettings frmConfiguration = new FormSettings();
            toolStripMenuItemConfiguration.Enabled = false;
            LoadForm(frmConfiguration);
        }
        private void toolStripMenuItemCloseAllWindows_Click(object sender, EventArgs e)
        {
            foreach (Form form in this.MdiChildren) form.Close();
            toolStripMenuItemCall.Enabled = toolStripMenuItemComplaints.Enabled = toolStripMenuItemConfiguration.Enabled = true;
        }
        private void toolStripMenuItemVertical_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.GetLength(0).Equals(0)) return;
            this.LayoutMdi(MdiLayout.TileVertical);
        }
        private void toolStripMenuItemHorizontal_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.GetLength(0).Equals(0)) return;
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }
        //General Purpose-Functions
        private void LoadForm(Form form)
        {
            form.MdiParent = this;
            form.WindowState = FormWindowState.Maximized;
            form.Show();
        }
        
        
        //public static void Start()
        //{
        //    this.Enabled = false;

        //}
        //public static void End()
        //{

        //}
    }
}